/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitee.minimalismstyle.fresh.oss.api.service

import com.gitee.minimalismstyle.fresh.common.api.OssApi
import com.gitee.minimalismstyle.fresh.common.api.annotation.ControllerFeignClient
import com.gitee.minimalismstyle.fresh.common.core.domain.QueryBody
import com.gitee.minimalismstyle.fresh.common.core.domain.QueryParams
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.common.core.domain.Simple
import com.gitee.minimalismstyle.fresh.oss.api.config.OssApiConst
import com.gitee.minimalismstyle.fresh.oss.api.model.OssFile
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
import java.io.OutputStream

/**
 * 文件信息业务接口
 * @author maoxiaodong
 */
@Api(value = "ossFile", tags = ["文件信息接口"])
@ControllerFeignClient(serviceId = OssApiConst.SERVICE_ID, ctx =OssApiConst.CTX, path = "/ossFile")
interface OssFileService: OssApi {

    /**
     * 保存文件
     * @param file
     * @return 文件信息
     */
    @ApiOperation("上传文件")
    @PutMapping(value = ["upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun save(@RequestPart("file") file: MultipartFile): R<OssFile>

    /**
     * 保存文件到具体批次上
     * @param file
     * @param batchId
     * @return 文件信息
     */
    @ApiOperation("上传文件")
    @PutMapping(value = ["upload/{batchId}"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun save(@RequestPart("file") file: MultipartFile, @PathVariable batchId: Long): R<OssFile>

    /**
     * 批量保存文件到具体批次上
     * @param files
     * @param batchId
     * @return 文件信息
     */
    @PutMapping(value = ["saveBatch/{batchId}"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun saveBatch(@RequestPart("files") files: List<MultipartFile>, @PathVariable batchId: Long): R<List<OssFile>>

    /**
     * 批量保存文件
     * @param files
     * @return 文件信息
     */
    @PutMapping(value = ["saveBatch"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun saveBatch(@RequestPart("files") files: List<MultipartFile>): R<List<OssFile>>

    /**
     * 根据id查找文件信息
     * @param id
     * @return
     */
    @GetMapping("{id}")
    fun findById(@PathVariable id: Long): R<OssFile>

    /**
     * 根据批次查找文件信息列表
     * @param batchId
     * @return
     */
    @GetMapping("findByBatchId/{batchId}")
    fun findByBatchId(@PathVariable batchId: Long): R<List<OssFile>>

    /**
     * 根据id删除文件
     * @param id
     * @return
     */
    @ApiOperation("删除文件")
    @DeleteMapping("{id}")
    override fun deleteById(@PathVariable id: Long): R<Int>

    /**
     * 根据批次删除一批文件
     * @param batchId
     * @return
     */
    @ApiOperation("删除文件")
    @DeleteMapping("deleteByBatchId/{batchId}")
    fun deleteByBatchId(@PathVariable batchId: Long): R<Int>

    /**
     * 根据id读取文件
     * @param id
     * @param os 文件流
     */
    fun read(id: Long, os: OutputStream)

    /**
     * 根据通用查询对象查询
     * @param params
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/findByQueryParams")
    fun findByQueryParams(params: QueryParams<Simple>): R<QueryBody<Simple>>
}